FROM modihq/yii2-dev:7.1-stretch

# --- 创建和主机登录用户相同 uid/gid 的用户 ---

ARG X_GID
ARG X_UID

RUN set -eux; \
    if [ -z "`getent group ${X_GID}`" ]; then \
        addgroup --system --gid ${X_GID} xu; \
    fi; \
    adduser --system --disabled-password --uid ${X_UID} --gid `getent group ${X_GID} | cut -d: -f3` xu

# --- 使用xu用户运行PHP-FPM的进程池 ---

RUN { \
        echo '[www]'; \
        echo; \
        echo "user = ${X_UID}"; \
        echo "group = ${X_GID}"; \
    } | tee /usr/local/etc/php-fpm.d/zzz.conf

# --- Composer ---

ENV COMPOSER_HOME /tmp/composer

RUN mkdir /tmp/composer && \
    chown xu:$X_GID /tmp/composer

# --- 定时任务 ---

COPY ./php/cron/crontab /etc/cron.d/xu

RUN chmod 644 /etc/cron.d/xu

WORKDIR /code

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
